package com.yunban.project.message.controller;

import com.yunban.project.message.dto.BusinessCardReq;
import com.yunban.project.message.resp.BusinessCardResp;
import com.yunban.project.message.service.BusinessCardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * Author:han
 * Date: 2024-05-21
 */
@RestController
@Tag(name = "业务名片模块")
@RequestMapping("/businessCard")
public class BusinessCardController {
    @Resource
    private BusinessCardService businessCardService;

    @NoNeedLogin
    @Operation(summary = "获取业务名片列表/不需要登录")
    @GetMapping("/common/list")
    public ResponseDTO<List<BusinessCardResp>> getCommonCards() {
        return ResponseDTO.ok(businessCardService.getBusinessCardList());
    }
    @Operation(summary = "获取业务名片列表/需要登录")
    @GetMapping("/list")
    public ResponseDTO<List<BusinessCardResp>> getCards() {
        return ResponseDTO.ok(businessCardService.getBusinessCardList());
    }

    @Operation(summary = "添加业务名片")
    @PostMapping("/info")
    public ResponseDTO<Boolean> addBusinessCard(@Validated @RequestBody BusinessCardReq businessCardReq) {
        return ResponseDTO.ok(businessCardService.saveBusinessCard(businessCardReq));
    }

    @PutMapping("/{id}")
    @Operation(summary = "修改业务名片")
    public ResponseDTO<Boolean> updateBusinessCard(@PathVariable long id,@Validated @RequestBody BusinessCardReq businessCardReq) {
        return ResponseDTO.ok( businessCardService.updateBusinessCard(id,businessCardReq));
    }

    @Operation(summary = "删除业务名片")
    @DeleteMapping("/{id}")
    public ResponseDTO<Boolean> deleteBusinessCard(@PathVariable long id) {
        return ResponseDTO.ok(businessCardService.remove(id));
    }
}
